package com.y3k.utils;

import java.util.Iterator;
import java.util.List;

import org.apache.log4j.Logger;

import com.y3k.mail.MailConfiguration;
import com.y3k.model.Configuration;
import com.y3k.model.Datasource;
import com.y3k.model.Notification;

public class ConfigurationUtil {

	public static final Logger log = Logger.getLogger(ConfigurationUtil.class);

	public static String PATH;
	
	public static List<Datasource> DATASOURCES = null;

	public static List<Notification> NOTIFICATIONS = null;

	public static Configuration CONFIGURATION = null;
	
	public static MailConfiguration MAIL = null;

	public static Datasource getDataSourceByName(String name) {
		for (Iterator<Datasource> it = DATASOURCES.iterator(); it.hasNext();) {
			Datasource datasource = it.next();
			if (name.equals(datasource.getName())) {
				return datasource;
			}
		}
		return null;
	}

	public static Datasource getDefaultDataSource() {
		for (Iterator<Datasource> it = DATASOURCES.iterator(); it.hasNext();) {
			Datasource datasource = it.next();
			if (datasource.getDefaultConnection()) {
				log.info("Default connection [" + datasource.getName() + "]");
				return datasource;
			}
		}
		return null;
	}
}